//
//  Add_ProgrammeViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/10/27.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Add_ProgrammeViewController.h"

#import "Remind_ListViewController.h"
#import "Participant_ListViewController.h"

@interface Add_ProgrammeViewController () <UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, UITextViewDelegate>

@property (nonatomic, strong) UIView * view_Bottom;

@property (nonatomic, strong) UITableView * tableView;

//
@property (nonatomic, strong) UITextView * textView;
@property (nonatomic, strong) UILabel * text_placeholder;

//
@property (nonatomic, strong) UILabel * time;
@property (nonatomic, strong) UILabel * person;
@property (nonatomic, strong) UILabel * remind;

@end

@implementation Add_ProgrammeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_bottomView];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"新建日程";
    _topView.backgroundColor = navi_bar_bg_color;
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(11, 35, 35, 15)];
    lbl_return.text = @"取消";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 50, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //
    UILabel * lbl_send = [[UILabel alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 10 - 35, 35, 35, 15)];
    lbl_send.text = @"发送";
    lbl_send.textColor = [UIColor whiteColor];
    lbl_send.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_send];
    
    UIButton * btn_send = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_send.frame = CGRectMake(SCREEN_WIDTH - 50, 22, 50, 40);
    [_topView addSubview:btn_send];
    [btn_send addTarget:self action:@selector(btn_sendAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右发送
- (void )btn_sendAction:(UIButton *)sender
{
//    NSLog(@"右发送");
    
    [self.textView resignFirstResponder];
    
    if([self.textView.text length] == 0)
    {
        self.text_placeholder.hidden = NO;
        
//        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"发送内容不能为空" preferredStyle:(UIAlertControllerStyleAlert)];
//        
//        [self presentViewController:alert animated:YES completion:^{
//        }];
//        
//        UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//        }];
//        [alert addAction:action];
    }
    else
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 50) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.tableFooterView = [[UIView alloc] init];
    [self.view addSubview:self.tableView];
    
//    //注册
//    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_AddProgramme"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        return 150.0f;
    }
    else
    {
        return 50.0f;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [[UITableViewCell alloc] init];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    if(indexPath.row == 0)
    {
        cell.backgroundColor = [UIColor whiteColor];
        
        //分割线
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(0, 135, SCREEN_WIDTH, 15)];
        view_Line.backgroundColor = [UIColor groupTableViewBackgroundColor];
        [cell addSubview:view_Line];
        
        //
        self.textView = [[UITextView alloc] initWithFrame:CGRectMake(10, 5, SCREEN_WIDTH - 20, 125)];
        self.textView.delegate = self;
        self.textView.backgroundColor = [UIColor whiteColor];
        self.textView.font = [UIFont systemFontOfSize:17.0f];
        
        [cell addSubview:self.textView];
        
        //
        self.text_placeholder = [[UILabel alloc] initWithFrame:CGRectMake(16, 16, 200, 15)];
        self.text_placeholder.text = @"请填写日程内容";
        self.text_placeholder.font = [UIFont systemFontOfSize:17.0f];
        self.text_placeholder.textColor = [UIColor grayColor];
        [cell addSubview:self.text_placeholder];
    }
    else if(indexPath.row == 1)
    {
        UIImageView * image_icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 20, 20)];
        image_icon.image = [UIImage imageNamed:@"time_blue.png"];
        image_icon.layer.masksToBounds = YES;
        [cell addSubview:image_icon];
        
        //
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_icon.frame) + 10, 15, 50, 20)];
        name.text = @"时间";
        name.textColor = [UIColor blackColor];
        name.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:name];
        
        //
        UIImageView * icon_return = [[UIImageView alloc] init];
        icon_return.layer.masksToBounds = YES;
        icon_return.frame = CGRectMake(SCREEN_WIDTH - 10 - 20, 15, 20, 20);
        icon_return.image = [UIImage imageNamed:@"rigth-return.png"];
        [cell addSubview:icon_return];
        
        //
        self.time = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 30, 15, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 30 - 30 - 10, 20)];
        self.time.text = @"2016年10月22日 09:22";
        self.time.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:self.time];

        //
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor grayColor];
        view_Line.alpha = 0.4f;
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 2)
    {
        UIImageView * image_icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 17.5, 20, 20)];
        image_icon.image = [UIImage imageNamed:@"involvement_blue.png"];
        image_icon.layer.masksToBounds = YES;
        [cell addSubview:image_icon];
        
        //
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_icon.frame) + 10, 15, 50, 20)];
        name.text = @"参与人";
        name.textColor = [UIColor blackColor];
        name.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:name];
        
        //
        UIImageView * icon_return = [[UIImageView alloc] init];
        icon_return.layer.masksToBounds = YES;
        icon_return.frame = CGRectMake(SCREEN_WIDTH - 10 - 20, 15, 20, 20);
        icon_return.image = [UIImage imageNamed:@"rigth-return.png"];
        [cell addSubview:icon_return];
        
        //
        self.person = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 30, 15, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 30 - 30 - 10, 20)];
        self.person.text = @"员工名称";
        self.person.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:self.person];
        
        //
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor grayColor];
        view_Line.alpha = 0.4f;
        [cell addSubview:view_Line];
    }
    else if(indexPath.row == 3)
    {
        UIImageView * image_icon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 17.5, 20, 20)];
        image_icon.image = [UIImage imageNamed:@"remind_blue.png"];
        image_icon.layer.masksToBounds = YES;
        [cell addSubview:image_icon];
        
        //
        UILabel * name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_icon.frame) + 10, 15, 50, 20)];
        name.text = @"提醒";
        name.textColor = [UIColor blackColor];
        name.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:name];
        
        //
        UIImageView * icon_return = [[UIImageView alloc] init];
        icon_return.layer.masksToBounds = YES;
        icon_return.frame = CGRectMake(SCREEN_WIDTH - 10 - 20, 15, 20, 20);
        icon_return.image = [UIImage imageNamed:@"rigth-return.png"];
        [cell addSubview:icon_return];
        
        //
        self.remind = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(name.frame) + 30, 15, SCREEN_WIDTH - CGRectGetMaxX(name.frame) - 30 - 30 - 10, 20)];
        self.remind.text = @"提醒事件";
        self.remind.font = [UIFont systemFontOfSize:15.0f];
        [cell addSubview:self.remind];
        
        //
        UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(15, 49, SCREEN_WIDTH - 15, 1)];
        view_Line.backgroundColor = [UIColor grayColor];
        view_Line.alpha = 0.4f;
        [cell addSubview:view_Line];
    }

    return cell;
}

- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 1)
    {
        NSLog(@"时间");
    }
    else if(indexPath.row == 2)
    {
//        NSLog(@"参与人");
        
        Participant_ListViewController * participant_ListViewController = [[Participant_ListViewController alloc] init];
        [self showViewController:participant_ListViewController sender:nil];
    }
    else if(indexPath.row == 3)
    {
//        NSLog(@"提醒");
        
        Remind_ListViewController * remind_ListViewController = [[Remind_ListViewController alloc] init];
        [self showViewController:remind_ListViewController sender:nil];
    }
}

#pragma mark - textView代理
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    self.text_placeholder.hidden = YES;
    
    return YES;
}

- (BOOL )textViewShouldEndEditing:(UITextView *)textView
{
    if([self.textView.text length] == 0)
    {
        self.text_placeholder.hidden = NO;
    }
    
    return YES;
}

#pragma mark - scrollView代理
- (void )scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self.textView resignFirstResponder];
}

#pragma mark - 底部视图
- (void )p_bottomView
{
    UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 50, SCREEN_WIDTH, 1)];
    view_Line.backgroundColor = [UIColor grayColor];
    view_Line.alpha = 0.5f;
    [self.view addSubview:view_Line];
    
    self.view_Bottom = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49, SCREEN_WIDTH, 49)];
    self.view_Bottom.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.view_Bottom];
    
    CGFloat length_x = SCREEN_WIDTH / 6;
    
    //表情
    UIImageView * image_smile = [[UIImageView alloc] initWithFrame:CGRectMake(length_x / 2 - 10, 15, 20, 20)];
    image_smile.layer.masksToBounds = YES;
    image_smile.image = [UIImage imageNamed:@"smile_black.png"];
    [self.view_Bottom addSubview:image_smile];
    
    UIButton * btn_smile = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_smile.frame = CGRectMake(0, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_smile];
    [btn_smile addTarget:self action:@selector(btn_smileAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //照相
    UIImageView * image_camera = [[UIImageView alloc] initWithFrame:CGRectMake(length_x + length_x / 2 - 10, 15, 20, 20)];
    image_camera.layer.masksToBounds = YES;
    image_camera.image = [UIImage imageNamed:@"camera_black.png"];
    [self.view_Bottom addSubview:image_camera];
    
    UIButton * btn_camera = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_camera.frame = CGRectMake(length_x, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_camera];
    [btn_camera addTarget:self action:@selector(btn_cameraAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //语音
    UIImageView * image_voice = [[UIImageView alloc] initWithFrame:CGRectMake(length_x * 2 + length_x / 2 - 10, 15, 20, 20)];
    image_voice.layer.masksToBounds = YES;
    image_voice.image = [UIImage imageNamed:@"voice_black.png"];
    [self.view_Bottom addSubview:image_voice];
    
    UIButton * btn_voice = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_voice.frame = CGRectMake(length_x * 2, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_voice];
    [btn_voice addTarget:self action:@selector(btn_voiceAction:) forControlEvents:(UIControlEventTouchUpInside)];

    //@ at_black.png
    UIImageView * image_at = [[UIImageView alloc] initWithFrame:CGRectMake(length_x * 3 + length_x / 2 - 10, 15, 20, 20)];
    image_at.layer.masksToBounds = YES;
    image_at.image = [UIImage imageNamed:@"at_black.png"];
    [self.view_Bottom addSubview:image_at];
    
    UIButton * btn_at = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_at.frame = CGRectMake(length_x * 3, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_at];
    [btn_at addTarget:self action:@selector(btn_atAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //定位 location_black.png
    UIImageView * image_location = [[UIImageView alloc] initWithFrame:CGRectMake(length_x * 4 + length_x / 2 - 10, 15, 20, 20)];
    image_location.layer.masksToBounds = YES;
    image_location.image = [UIImage imageNamed:@"location_black.png"];
    [self.view_Bottom addSubview:image_location];
    
    UIButton * btn_location = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_location.frame = CGRectMake(length_x * 4, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_location];
    [btn_location addTarget:self action:@selector(btn_locationAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //添加  add_black.png
    UIImageView * image_add = [[UIImageView alloc] initWithFrame:CGRectMake(length_x * 5 + length_x / 2 - 10, 15, 20, 20)];
    image_add.layer.masksToBounds = YES;
    image_add.image = [UIImage imageNamed:@"add_black.png"];
    [self.view_Bottom addSubview:image_add];
    
    UIButton * btn_add = [UIButton buttonWithType:(UIButtonTypeCustom)];
    btn_add.frame = CGRectMake(length_x * 5, 0, length_x, 49);
    [self.view_Bottom addSubview:btn_add];
    [btn_add addTarget:self action:@selector(btn_addAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark - 点击弹出表情
- (void )btn_smileAction:(UIButton *)sender
{
    NSLog(@"点击弹出表情");
}

#pragma mark - 点击照相选择
- (void )btn_cameraAction:(UIButton *)sender
{
    NSLog(@"点击照相选择");
}

#pragma mark - 点击切换语音
- (void )btn_voiceAction:(UIButton *)sender
{
    NSLog(@"点击切换语音");
}

#pragma mark - 点击@谁
- (void )btn_atAction:(UIButton *)sender
{
    NSLog(@"点击@谁");
}

#pragma mark - 点击定位
- (void )btn_locationAction:(UIButton *)sender
{
    NSLog(@"点击定位");
}

#pragma mark - 点击添加更多
- (void )btn_addAction:(UIButton *)sender
{
    NSLog(@"点击添加更多");
}












@end
